﻿
#ifndef LINKINTERFACE_H
#define LINKINTERFACE_H


#include  <QObject>
#include  <QThread>

#include  <memory>
#include "Stdafx.h"

class LinkManager;
class LinkInterface : public QObject
{
    Q_OBJECT
public:
    using ptr = QSharedPointer<LinkInterface>;

    friend LinkManager;
    typedef enum {
        Serial = 0,
        Tcp = 1,
        Modbus = 2,
        UnKnow = 3
    }link_type_t;
    Q_ENUM(link_type_t)

    Q_PROPERTY_READONLY_AUTO(link_type_t, type)
public:
    explicit LinkInterface               (QObject *parent,link_type_t type);
    virtual ~LinkInterface               () {}
    virtual bool       connect           () = 0;
    virtual void       disConnect        () = 0;
    virtual bool       isConnected       () = 0;
    static QString     typeToString      (link_type_t type);
signals:
    void bytesReceived      (LinkInterface* link, QByteArray data);
    void bytesSent          (LinkInterface* link, QByteArray data);
    void connectedChanged   (bool isConnected);
    void communicationError (const QString& title, const QString& error);
public slots:
    virtual void writeBytes(QByteArray bytes){};
};



#endif // LINKINTERFACE_H
